/**  
 * 文 件 名: UserMgrAction.java  
 * 描    述：   
 * 版    权：Copyright (c)20012-2012 tongzhou All Rights Reserved.
 * 公    司: 同舟 
 * 作    者：彭定雄                     
 * 版    本: 1.0  
 * 创建时间: 2012-10-27
 *  
 * 修改历史：  
 * 时间                             作者                       版本                        描述  
 * ------------------------------------------------------------------  
 * 2012-10-27        彭定雄                1.0          1.0 Version  
 */         

/**
 * 
 */
package com.tongzhou.tongzhou.account.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.account.dao.IAccountContactDAO;
import com.tongzhou.tongzhou.account.model.AccountContact;
import com.tongzhou.tongzhou.account.model.SearchAccountCondition;
import com.tongzhou.tongzhou.account.model.SearchAccountContactCondition;

public class AccountClientAction extends ActionSupport{
	private int id;
	private int account_id;
	private AccountContact contact;
	private List<AccountContact> result=null;
	private SearchAccountContactCondition condition=null;
	
	private int pageSize ;
	private int currentPage ;
	private String orderBy ;
	private String orderByType ;
	
	private IAccountContactDAO dao=null;
	/**
	 * 用户列表界面
	 *@author: 彭定雄
	 *@return 
	 *@throws DBException
	 */
	public String listAccountContact() throws DBException{
		checkSearchCondition();
		condition = new SearchAccountContactCondition();
		if (currentPage == 0){
			currentPage = 1;
		}
		condition.setCurrentPage(currentPage) ;
		condition.setOrderBy(orderBy);
		condition.setOrderByType(orderByType) ;
		condition.setPageSize(pageSize) ;
		if(contact==null){
			condition.setAccount_id(account_id);
		}else{
			condition.setAccount_id(contact.getAccount_id());
		}
	    result = dao.listAccountContact(condition);
		return "listAccountContact";
	} 
	
	
	/**
	 * 设置列表显示格式
	 *@author: 彭定雄
	 */
	private void checkSearchCondition(){
		if(currentPage <=0){
			currentPage = 1 ;
		}
		
		if(pageSize<=0){
			pageSize = 10 ;
		}
		
		if(orderBy==null||"".equals(orderBy)){
			orderBy = "id" ;
		}
		
		if(orderByType == null || "".equals(orderByType)){
			orderByType = "desc" ;
		}
	}
	
	/**
	 * 新增用户
	 *@author: 彭定雄
	 *@return
	 *@throws DBException
	 */
	public String toAddAccountContact() throws DBException{
		return "addAccountContact";
	}
	
	public String addAccountContact() throws DBException{
		dao.addAccountContact(contact);
		listAccountContact();
		return "listAccountContact";
	}
	
	public String deleteAccountContact() throws DBException{
//		dao=new UserMgrDAO();
		dao.deleteAccountContact(id);
		listAccountContact();
		return "listAccountContact";
	}
	
	public String toEditAccountContact() throws DBException{
		contact=dao.getAccountContactById(id);
		return "editAccountContact";
	}
	
	public String editAccountContact() throws DBException{
		dao.updateAccountContact(contact);
		listAccountContact();
		return "listAccountContact";
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public AccountContact getContact() {
		return contact;
	}


	public void setContact(AccountContact contact) {
		this.contact = contact;
	}


	public List<AccountContact> getResult() {
		return result;
	}


	public void setResult(List<AccountContact> result) {
		this.result = result;
	}


	public int getAccount_id() {
		return account_id;
	}


	public void setAccount_id(int accountId) {
		account_id = accountId;
	}


	public SearchAccountContactCondition getCondition() {
		return condition;
	}


	public void setCondition(SearchAccountContactCondition condition) {
		this.condition = condition;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public String getOrderBy() {
		return orderBy;
	}


	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}


	public String getOrderByType() {
		return orderByType;
	}


	public void setOrderByType(String orderByType) {
		this.orderByType = orderByType;
	}


	public IAccountContactDAO getDao() {
		return dao;
	}


	public void setDao(IAccountContactDAO dao) {
		this.dao = dao;
	}

}
